<form class="layui-form" action="{:url()}" method="post" id="editForm">
    
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券名称</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-quan_name" name="quan_name" autocomplete="off" lay-verify="required"  placeholder="请输入优惠券名称">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券类型</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-type" name="type" autocomplete="off"   value="代金券" disabled="disabled">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠券描述</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-quan_desc" name="quan_desc" autocomplete="off"  placeholder="请输入优惠券描述">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">发放对象</label>
        <div class="layui-input-inline w200">
            <select name="user_type" id="" class="layui-input field-user_type">
                <option value="0">所有用户</option>
                <option value="1">内部员工</option>
                <option value="2">销售人员</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否对外发放</label>
        <div class="layui-input-inline w200">
            <select name="status" id="" class="layui-input field-status">
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">领取时间</label>
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 160px;">
                <input type="text" class="layui-input field-get_bg_time" id="get_bg_time"name="get_bg_time" placeholder="开始时间">
            </div>
            <div class="layui-form-mid">至</div>
            <div class="layui-input-inline" style="width: 160px;">
                <input type="text" class="layui-input field-get_end_time" id="get_end_time" name="get_end_time" placeholder="结束时间">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">使用时间</label>
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 160px;">
                <input type="text" class="layui-input field-use_bg_time" id="use_bg_time"name="use_bg_time" placeholder="开始时间">
            </div>
            <div class="layui-form-mid">至</div>
            <div class="layui-input-inline" style="width: 160px;">
                <input type="text" class="layui-input field-use_end_time" id="use_end_time" name="use_end_time" placeholder="结束时间">
            </div>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">发券总量</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-rest_num" name="rest_num" autocomplete="off">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">每人限领</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-get_limit_num" name="get_limit_num" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">使用门槛</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-money_begin" name="money_begin" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">满减金额</label>
        <div class="layui-input-inline">
            <input type="text" data-disabled class="layui-input field-money_del" name="money_del" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" class="field-id" name="id">
        </div>
    </div>
    <div class="pop-bottom-bar hisi-footer">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" lay-data="{pop: true, refresh: true}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>
{include file="system@block/layui" /}
<script>
var s = "";
layui.use(['func'], function() {
    layui.func.assign({:json_encode($formData)});
});

layui.use(["jquery", "upload", "form", "layer", "element"], function () {
    var $ = layui.$,
        element = layui.element,
        layer = layui.layer,
        upload = layui.upload,
        form = layui.form;
    

    //拖拽上传
    var uploadInst = upload.render({
        elem: '#headImg'
        , url: '{:url("system/annex/upload?water=&thumb=&from=&group=")}'
        , multiple: true
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                // $('#demo1').attr('src', result); //图片链接（base64）
                $('#demo2').append('<img src="' + result
                    + '" alt="' + file.name
                    + '"height="100px" width="100px" class="layui-upload-img uploadImgPreView">')


            });
        }
        , done: function (res) {
            console.log(res);
            //上传完毕
            if (res.code == 1) {
                console.log(666);
                var last_url = $("#banner").val();
                var upload_image_url = "";
                if(last_url){
                    upload_image_url = last_url+","+res.data.file;
                }else {
                    upload_image_url = res.data.file;
                }
                // console.log(upload_image_url);
                $("#banner").val(upload_image_url);
            }
        }           
        , error: function () {
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
        
    });
});

layui.use([ 'laydate'], function() {
    var form = layui.form,
        layer = layui.layer,
        layedit = layui.layedit,
        laydate = layui.laydate;
    var endDate = laydate.render({
        elem: '#get_end_time', 
        type:'datetime',
        // eventElem: '.date-input-icon',
        // max: getCurrentDate(),
        done: function(value, date) {
            startDate.config.max = {
                year: date.year,
                month: date.month - 1, 
                date: date.date,
            }
        }
    });
    var startDate = laydate.render({
        elem: '#get_bg_time',
        type:'datetime',
        // eventElem: '.date-input-icon',
        // max: getCurrentDate(), 
        done: function(value, date) {
            endDate.config.min = {
                year: date.year,
                month: date.month - 1, 
                date: date.date,
            };
        }
    });

    var endDates = laydate.render({
        elem: '#use_end_time', 
        type:'datetime',
        // eventElem: '.date-input-icon',
        // max: getCurrentDate(),
        done: function(value, date) {
            startDate.config.max = {
                year: date.year,
                month: date.month - 1, 
                date: date.date,
            }
        }
    });
    var startDates = laydate.render({
        elem: '#use_bg_time',
        type:'datetime',
        // eventElem: '.date-input-icon',
        // max: getCurrentDate(), 
        done: function(value, date) {
            endDate.config.min = {
                year: date.year,
                month: date.month - 1, 
                date: date.date,
            };
        }
    });
});
</script>
